<script>
	import { clearGlobalEventListeners } from "@/config/eventListener";

	export default {
		onLaunch() {
			console.log('App Launch');
			this.initEventListeners();
		},
		onShow() {
			console.log('App Show');
		},
		onHide() {
			console.log('App Hide');
		},
		beforeDestroy() {
			this.cleanupEventListeners();
		},
		methods: {
			initEventListeners() {
				// #ifdef H5
				try {
					window.addEventListener('beforeunload', this.handleBeforeUnload);
				} catch (error) {
					console.error('初始化事件监听失败:', error);
				}
				// #endif
			},
			cleanupEventListeners() {
				// #ifdef H5
				try {
					window.removeEventListener('beforeunload', this.handleBeforeUnload);
				} catch (error) {
					console.error('移除事件监听失败:', error);
				}
				// #endif
				this.handleBeforeUnload();
			},
			handleBeforeUnload() {
				try {
					clearGlobalEventListeners();
				} catch (error) {
					console.error('清理全局事件失败:', error);
				}
			}
		}
	}
</script>

<style lang="scss">
	/*每个页面公共css */
	@import 'uview-ui/index.scss';
	@import '@/styles/global.scss';
</style>